package com.xiaoyun.activiti03;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.Map;

public class VariableTest {
    //zhangsan完成任务-lisi
    public static void main1(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        TaskService taskService = processEngine.getTaskService();
        String key = "myProcess_1";
        Task task = taskService.createTaskQuery()
                .processDefinitionKey(key)
                .taskAssignee("zhaoliu").singleResult();

        if (task != null) {
            taskService.complete(task.getId());
            System.out.println("任务执行完毕");
        }


    }

    //启动流程实例
    public static void main2(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RuntimeService runtimeService = processEngine.getRuntimeService();

        String key = "myProcess_1";
        Map<String, Object> map = new HashMap<>();

        Holiday holiday = new Holiday();
        holiday.setNum(5F);

        map.put("holiday", holiday);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key, map);

        System.out.println(processInstance.getName());
        System.out.println(processInstance.getProcessDefinitionId());

    }

    public static void main(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("diagram/holiday4.bpmn")
                .addClasspathResource("diagram/holiday4.png")
                .name("请假流程-流程变量")
                .deploy();
        System.out.println(deploy.getId());
    }
}
